package uit.qlks.from;

/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */

import java.sql.ResultSetMetaData;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import javax.sql.rowset.WebRowSet;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.JTextComponent;
import uit.ejb.dto.LoaiPhongDTO;
import uit.ejb.dto.PhongDTO;
import uit.qlks.baocao.BaoCao;
import uit.qlks.controller.loaiphong.LoaiPhongCotroller;
import uit.qlks.controller.phong.PhongController;

/**
 *
 * @author Restart
 */
public class frmPhong extends javax.swing.JFrame {

    /**
     * Creates new form frmPhong
     */
    public static int flagLoaiPhong = 0;
    public static int flagPhong = 0;
    public static int flagTab = 0;
    public List combobox = new ArrayList();
    public frmPhong() {
        initComponents();
    }

    // Lấy danh sách loại phòng
    private void LayDanhSachLoaiPhong() {
        try{
            WebRowSet wrs = LoaiPhongCotroller.loaiPhong_GetByAll();
            String[] tableColumnsName = {"Mã Loại Phòng","Tên Loại Phòng", "Giá (VNĐ)"};
            this.UpdateTable(this.jtbDanhSachLoaiPhong, tableColumnsName, wrs);
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(new JFrame(), "Đường truyền bị gián đoạn ! Xin vui lòng kiểm tra lại", "Test Connect", JOptionPane.INFORMATION_MESSAGE);
        }
    }
    
    // Lấy danh sách phòng
    private void LayDanhSachPhong(){
        try{
            WebRowSet wrs = PhongController.phong_GetByAll();
            String[] tableColumnsName = {"Mã Phòng","Tên Phòng", "Mã Loại Phòng","Loại Phòng", "Trạng Thái", "Ghi Chú"};
            this.UpdateTable(this.jtDanhSachPhong, tableColumnsName, wrs);
        }
        catch(Exception e)
        {
             JOptionPane.showMessageDialog(new JFrame(), "Đường truyền bị gián đoạn ! Xin vui lòng kiểm tra lại", "Test Connect", JOptionPane.INFORMATION_MESSAGE);
        }
    }

    private void LayThongTinLoaiPhong() {
        // TODO add your handling code here:
            try{
                this.txtLoaiPhong.setText(jtbDanhSachLoaiPhong.getValueAt(this.jtbDanhSachLoaiPhong.getSelectedRow(), 1).toString());
                this.txtGia.setText(jtbDanhSachLoaiPhong.getValueAt(this.jtbDanhSachLoaiPhong.getSelectedRow(), 2).toString().replace(".", ""));
            }
            catch(Exception e)
            {
            }
    }

    private void LayThongTinPhong() {
    // TODO add your handling code here:
        try{
            int row = this.jtDanhSachPhong.getSelectedRow();
            this.txtPhong.setText(jtDanhSachPhong.getValueAt(row, 1).toString());
            cmbLoaiPhong.setSelectedIndex(combobox.indexOf(jtDanhSachPhong.getValueAt(row, 2).toString().substring(3)));
            cmbTinhTrang.setSelectedItem(jtDanhSachPhong.getValueAt(row, 4).toString());
            this.txaGhiChu.setText(jtDanhSachPhong.getValueAt(row, 5).toString());
        }
        catch(Exception e)
        {
        }
    }
    List MaLP = new ArrayList();
    // Đổ dữ liệu từ WebRowSet vào table
    private void UpdateTable(JTable jt, String[] tableColumnsName, WebRowSet wrs){
        try{
            MaLP.clear();
            DefaultTableModel dfTable = (DefaultTableModel) jt.getModel();
            dfTable.getDataVector().removeAllElements();
            dfTable.setColumnIdentifiers(tableColumnsName);
            ResultSetMetaData rsmd = wrs.getMetaData();
            int count = rsmd.getColumnCount();
            Vector rowdata;
            if(count <= 3 )//bang LoaiPhong
            {
                while(wrs.next()){
                   // Object[] objects = new Object[count];
                    rowdata = new Vector();
                    rowdata.add("MLP"+wrs.getString("MaLoaiPhong"));
                    rowdata.add(wrs.getString("TenLoaiPhong"));
                    rowdata.add(Format_Price(wrs.getString("Gia").replace(".0", "")));
                    dfTable.addRow(rowdata);
                }
            }
            else
            {
                String[] tinhtrang = {"Đã Thuê", "Trống"};
                 while(wrs.next()){
                   // Object[] objects = new Object[count];
                    rowdata = new Vector();
                    rowdata.add("MP"+wrs.getString("MaPhong"));
                    rowdata.add(wrs.getString("TenPhong"));
                    MaLP.add(wrs.getString("MaLoaiPhong"));
                    WebRowSet rs = LoaiPhongCotroller.loaiPhong_GetById(wrs.getString("MaLoaiPhong").toString());
                    while(rs.next())
                    {
                        rowdata.add("MLP"+rs.getString("MaLoaiPhong"));
                        MaLP.add(rs.getString("MaLoaiPhong"));
                        rowdata.add(rs.getString("TenLoaiPhong"));
                    }
                    rowdata.add(tinhtrang[wrs.getInt("TinhTrang")]);
                    rowdata.add(wrs.getString("GhiChu"));

                    dfTable.addRow(rowdata);
                }
            }
//            jt.setModel(dfTable);
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }
    
    private boolean KiemTraTextbox(JTextComponent a, JTextComponent b)
    {
        if(b!=null)
        {
            if(a.getText().equals("") || b.getText().equals(""))
            {
                JOptionPane.showMessageDialog(this, "Xin hãy đầy đủ thông tin !!");
                return true;
            }
        }
        else
        {
            if(a.getText().equals(""))
            {
                JOptionPane.showMessageDialog(this, "Xin hãy đầy đủ thông tin !!");
                return true;
            }
        }
        return false;
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtLoaiPhong = new javax.swing.JTextField();
        txtGia = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        btnLuu = new javax.swing.JButton();
        btnSua = new javax.swing.JButton();
        btnXoa = new javax.swing.JButton();
        btnThem = new javax.swing.JButton();
        btnTroLai = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtbDanhSachLoaiPhong = new javax.swing.JTable();
        btnPrint = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtPhong = new javax.swing.JTextField();
        cmbLoaiPhong = new javax.swing.JComboBox();
        btnThem2 = new javax.swing.JButton();
        btnXoa2 = new javax.swing.JButton();
        btnSua2 = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        txaGhiChu = new javax.swing.JTextArea();
        jLabel9 = new javax.swing.JLabel();
        btnLuu2 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtDanhSachPhong = new javax.swing.JTable();
        btnTroLai2 = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        cmbTinhTrang = new javax.swing.JComboBox();
        btnSearch = new javax.swing.JButton();
        txtSearch = new javax.swing.JTextField();
        btnPrint1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("QUẢN LÝ PHÒNG");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        jTabbedPane1.setFont(new java.awt.Font("Times New Roman", 0, 14));
        jTabbedPane1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jTabbedPane1StateChanged(evt);
            }
        });

        jPanel2.setName("jpnLoaiPhong"); // NOI18N
        jPanel2.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                jPanel2ComponentShown(evt);
            }
        });
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel4.setText("Tên:");
        jPanel2.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 229, -1, -1));

        jLabel5.setText("Giá:");
        jPanel2.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(13, 267, -1, -1));

        txtLoaiPhong.setEnabled(false);
        txtLoaiPhong.setName("txtTenLoaiPhong"); // NOI18N
        jPanel2.add(txtLoaiPhong, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 226, 172, -1));

        txtGia.setEnabled(false);
        txtGia.setName("txtGiaLoaiPhong"); // NOI18N
        txtGia.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtGiaKeyTyped(evt);
            }
        });
        jPanel2.add(txtGia, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 264, 172, -1));

        jLabel6.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabel6.setText("Danh Sách Loại Phòng");
        jPanel2.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(491, 19, -1, -1));

        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/home.png"))); // NOI18N
        jPanel2.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 96, -1, -1));

        btnLuu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Save.png"))); // NOI18N
        btnLuu.setText("Lưu");
        btnLuu.setToolTipText("Lưu");
        btnLuu.setBorder(null);
        btnLuu.setContentAreaFilled(false);
        btnLuu.setEnabled(false);
        btnLuu.setName("btnLuu"); // NOI18N
        btnLuu.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Save2.png"))); // NOI18N
        btnLuu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLuuActionPerformed(evt);
            }
        });
        jPanel2.add(btnLuu, new org.netbeans.lib.awtextra.AbsoluteConstraints(307, 414, -1, -1));

        btnSua.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Edit.png"))); // NOI18N
        btnSua.setText("Sửa");
        btnSua.setToolTipText("Sửa");
        btnSua.setBorder(null);
        btnSua.setContentAreaFilled(false);
        btnSua.setName("btnSua"); // NOI18N
        btnSua.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Edit2.png"))); // NOI18N
        btnSua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSuaActionPerformed(evt);
            }
        });
        jPanel2.add(btnSua, new org.netbeans.lib.awtextra.AbsoluteConstraints(219, 414, -1, -1));

        btnXoa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Delete.png"))); // NOI18N
        btnXoa.setText("Xóa");
        btnXoa.setToolTipText("Xóa");
        btnXoa.setBorder(null);
        btnXoa.setContentAreaFilled(false);
        btnXoa.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Delete2.png"))); // NOI18N
        btnXoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnXoaActionPerformed(evt);
            }
        });
        jPanel2.add(btnXoa, new org.netbeans.lib.awtextra.AbsoluteConstraints(131, 414, -1, -1));

        btnThem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Add.png"))); // NOI18N
        btnThem.setText("Thêm");
        btnThem.setToolTipText("Thêm");
        btnThem.setBorder(null);
        btnThem.setContentAreaFilled(false);
        btnThem.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Add2.png"))); // NOI18N
        btnThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThemActionPerformed(evt);
            }
        });
        jPanel2.add(btnThem, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 414, -1, -1));

        btnTroLai.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/back.png"))); // NOI18N
        btnTroLai.setText("Trở lại");
        btnTroLai.setToolTipText("Trở lại");
        btnTroLai.setBorder(null);
        btnTroLai.setContentAreaFilled(false);
        btnTroLai.setEnabled(false);
        btnTroLai.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/back2.png"))); // NOI18N
        btnTroLai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTroLaiActionPerformed(evt);
            }
        });
        jPanel2.add(btnTroLai, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 414, -1, -1));

        jtbDanhSachLoaiPhong.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jtbDanhSachLoaiPhong.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Mã Loại Phòng", "Tên Loại Phòng", "Giá"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtbDanhSachLoaiPhong.setName("jtbDanhSachLoaiPhong"); // NOI18N
        jtbDanhSachLoaiPhong.getTableHeader().setReorderingAllowed(false);
        jtbDanhSachLoaiPhong.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jtDanhSachLoaiPhong_MouserPress(evt);
            }
        });
        jScrollPane2.setViewportView(jtbDanhSachLoaiPhong);

        jPanel2.add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 50, 649, 316));

        btnPrint.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Printer.png"))); // NOI18N
        btnPrint.setText("In");
        btnPrint.setToolTipText("In");
        btnPrint.setBorder(null);
        btnPrint.setContentAreaFilled(false);
        btnPrint.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Printer2.png"))); // NOI18N
        btnPrint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPrintActionPerformed(evt);
            }
        });
        jPanel2.add(btnPrint, new org.netbeans.lib.awtextra.AbsoluteConstraints(487, 414, -1, -1));
        btnPrint.getAccessibleContext().setAccessibleName("");

        jTabbedPane1.addTab("Loại phòng", jPanel2);

        jPanel1.setName("jpnPhong"); // NOI18N

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 13));
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/resort.png"))); // NOI18N

        jLabel2.setText("Phòng:");

        jLabel3.setText("Loại phòng:");

        txtPhong.setName("txtPhong"); // NOI18N

        cmbLoaiPhong.setEnabled(false);
        cmbLoaiPhong.setName("cmbLoaiPhong"); // NOI18N

        btnThem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Add.png"))); // NOI18N
        btnThem2.setText("Thêm");
        btnThem2.setToolTipText("Thêm");
        btnThem2.setBorder(null);
        btnThem2.setContentAreaFilled(false);
        btnThem2.setName("btnThem"); // NOI18N
        btnThem2.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Add2.png"))); // NOI18N
        btnThem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThem2ActionPerformed(evt);
            }
        });

        btnXoa2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Delete.png"))); // NOI18N
        btnXoa2.setText("Xóa");
        btnXoa2.setToolTipText("Xóa");
        btnXoa2.setBorder(null);
        btnXoa2.setContentAreaFilled(false);
        btnXoa2.setName("btnXoa"); // NOI18N
        btnXoa2.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Delete2.png"))); // NOI18N
        btnXoa2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnXoa2ActionPerformed(evt);
            }
        });

        btnSua2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Edit.png"))); // NOI18N
        btnSua2.setText("Sửa");
        btnSua2.setToolTipText("Sửa");
        btnSua2.setBorder(null);
        btnSua2.setContentAreaFilled(false);
        btnSua2.setName("btnSua"); // NOI18N
        btnSua2.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Edit2.png"))); // NOI18N
        btnSua2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSua2ActionPerformed(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("Times New Roman", 1, 18));
        jLabel8.setText("Danh Sách Phòng");

        txaGhiChu.setColumns(20);
        txaGhiChu.setRows(5);
        txaGhiChu.setEnabled(false);
        jScrollPane3.setViewportView(txaGhiChu);

        jLabel9.setText("Ghi chú:");

        btnLuu2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Save.png"))); // NOI18N
        btnLuu2.setText("Lưu");
        btnLuu2.setToolTipText("Lưu");
        btnLuu2.setBorder(null);
        btnLuu2.setContentAreaFilled(false);
        btnLuu2.setEnabled(false);
        btnLuu2.setName("btnLuu"); // NOI18N
        btnLuu2.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Save2.png"))); // NOI18N
        btnLuu2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLuu2ActionPerformed(evt);
            }
        });

        jtDanhSachPhong.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4", "Title 5", "Title 6"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtDanhSachPhong.setName("jtbDanhSachPhong"); // NOI18N
        jtDanhSachPhong.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jtDanhSachPhongMousePressed(evt);
            }
        });
        jScrollPane1.setViewportView(jtDanhSachPhong);

        btnTroLai2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/back.png"))); // NOI18N
        btnTroLai2.setText("Trở lại");
        btnTroLai2.setToolTipText("Trở Lại");
        btnTroLai2.setActionCommand("btnTroLai");
        btnTroLai2.setBorder(null);
        btnTroLai2.setContentAreaFilled(false);
        btnTroLai2.setEnabled(false);
        btnTroLai2.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/back2.png"))); // NOI18N
        btnTroLai2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTroLai2ActionPerformed(evt);
            }
        });

        jLabel10.setText("Tình trạng:");

        cmbTinhTrang.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Đã Thuê", "Trống" }));
        cmbTinhTrang.setEnabled(false);

        btnSearch.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Search-icon.png"))); // NOI18N
        btnSearch.setText("Tìm");
        btnSearch.setBorder(null);
        btnSearch.setContentAreaFilled(false);
        btnSearch.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Search-icon2.png"))); // NOI18N
        btnSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchActionPerformed(evt);
            }
        });

        btnPrint1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Printer.png"))); // NOI18N
        btnPrint1.setText("Print");
        btnPrint1.setBorder(null);
        btnPrint1.setContentAreaFilled(false);
        btnPrint1.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Printer2.png"))); // NOI18N
        btnPrint1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPrint1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(72, 72, 72)
                        .addComponent(jLabel1))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(38, 38, 38)
                        .addComponent(txtPhong, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(cmbLoaiPhong, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addGap(21, 21, 21)
                        .addComponent(cmbTinhTrang, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(13, 13, 13)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(208, 208, 208)
                        .addComponent(jLabel8)
                        .addGap(40, 40, 40)
                        .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27)
                        .addComponent(btnSearch))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(13, 13, 13)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 653, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(30, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addComponent(btnThem2)
                .addGap(38, 38, 38)
                .addComponent(btnXoa2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 47, Short.MAX_VALUE)
                .addComponent(btnSua2)
                .addGap(43, 43, 43)
                .addComponent(btnLuu2)
                .addGap(44, 44, 44)
                .addComponent(btnTroLai2)
                .addGap(42, 42, 42)
                .addComponent(btnPrint1)
                .addGap(412, 412, 412))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(3, 3, 3)
                                .addComponent(jLabel2))
                            .addComponent(txtPhong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(29, 29, 29)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(3, 3, 3)
                                .addComponent(jLabel3))
                            .addComponent(cmbLoaiPhong, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(31, 31, 31)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(3, 3, 3)
                                .addComponent(jLabel10))
                            .addComponent(cmbTinhTrang, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(57, 57, 57)
                                .addComponent(jLabel9))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(21, 21, 21)
                                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(3, 3, 3)
                                .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(2, 2, 2)
                                .addComponent(btnSearch)))
                        .addGap(14, 14, 14)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE)))
                .addGap(47, 47, 47)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(btnThem2)
                        .addComponent(btnXoa2))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(btnPrint1)
                        .addComponent(btnTroLai2, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnLuu2)
                        .addComponent(btnSua2)))
                .addContainerGap())
        );

        txtPhong.getAccessibleContext().setAccessibleName("txtPhong");
        cmbLoaiPhong.getAccessibleContext().setAccessibleName("cmbLoaiPhong");
        btnThem2.getAccessibleContext().setAccessibleName("btnThem");
        btnXoa2.getAccessibleContext().setAccessibleName("btnXoa");
        btnSua2.getAccessibleContext().setAccessibleName("btnSua");

        jTabbedPane1.addTab("Phòng", jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 948, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 509, Short.MAX_VALUE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-964)/2, (screenSize.height-547)/2, 964, 547);
    }// </editor-fold>//GEN-END:initComponents

private void jtDanhSachLoaiPhong_MouserPress(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtDanhSachLoaiPhong_MouserPress
        LayThongTinLoaiPhong();
}//GEN-LAST:event_jtDanhSachLoaiPhong_MouserPress

private void btnLuuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLuuActionPerformed
// TODO add your handling code here:
    if(this.KiemTraTextbox(this.txtLoaiPhong, this.txtGia))
        return;
    if(flagLoaiPhong == 1)//Sửa
    {
        LoaiPhongDTO lp = new LoaiPhongDTO();
        lp.setMaLoaiPhong(jtbDanhSachLoaiPhong.getValueAt(this.jtbDanhSachLoaiPhong.getSelectedRow(), 0).toString().substring(3));
        lp.setTenLoaiPhong(this.txtLoaiPhong.getText().toString());
        lp.setGia(this.txtGia.getText().toString());
        try{
            if(JOptionPane.showConfirmDialog(this, "Bạn có chắc chắn  muốn sửa không ?", "Question",JOptionPane.YES_NO_OPTION)!=1)
            {
                if(LoaiPhongCotroller.loaiPhong_Update(lp)){
                    JOptionPane.showMessageDialog(this, "Sửa thành công !!");
                    this.LayDanhSachLoaiPhong();
                    frmPhong.flagLoaiPhong = 0;
                    this.btnThem.setEnabled(true);
                    this.btnXoa.setEnabled(true);
                    this.btnLuu.setEnabled(false);
                    this.btnTroLai.setEnabled(false);
                    txtLoaiPhong.setEnabled(false);
                    txtGia.setEnabled(false);
                }
            }
            else
            {
                return;
            }
        }
        catch(Exception e)
        {
             JOptionPane.showMessageDialog(new JFrame(), "Đường truyền bị gián đoạn ! Xin vui lòng kiểm tra lại", "Test Connect", JOptionPane.INFORMATION_MESSAGE);
        }
    }
    if(frmPhong.flagLoaiPhong == 2)//Thêm
    {
        LoaiPhongDTO lp = new LoaiPhongDTO();
        lp.setMaLoaiPhong(null);
        lp.setTenLoaiPhong(this.txtLoaiPhong.getText().toString());
        lp.setGia(this.txtGia.getText().toString());
        try{
            if(LoaiPhongCotroller.loaiPhong_Insert(lp)){
                JOptionPane.showMessageDialog(this, "Thêm Thành Công !!");
                this.LayDanhSachLoaiPhong();
                flagLoaiPhong = 0;
                this.txtLoaiPhong.setEnabled(false);
                this.txtGia.setEnabled(false);
                this.btnThem.setEnabled(true);
                this.btnXoa.setEnabled(true);
                this.btnSua.setEnabled(true);
                this.btnLuu.setEnabled(false);
                this.btnTroLai.setEnabled(false);
            }

        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(new JFrame(), "Đường truyền bị gián đoạn ! Xin vui lòng kiểm tra lại", "Test Connect", JOptionPane.INFORMATION_MESSAGE);
        }
    }
    this.txtLoaiPhong.setText("");
    this.txtGia.setText("");
}//GEN-LAST:event_btnLuuActionPerformed

private void btnSuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSuaActionPerformed
// TODO add your handling code here:
    int i = this.jtbDanhSachLoaiPhong.getSelectedRow();
    if(i == -1)
    {
        JOptionPane.showMessageDialog(this, "Xin vui lòng chọn loại phòng cần sửa");
    }
    else
    {
        this.btnThem.setEnabled(false);
        this.btnXoa.setEnabled(false);
        this.btnLuu.setEnabled(true);
        this.btnTroLai.setEnabled(true);
        this.txtLoaiPhong.setEnabled(true);
        this.txtGia.setEnabled(true);
        frmPhong.flagLoaiPhong = 1;
    }
}//GEN-LAST:event_btnSuaActionPerformed

private void btnXoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnXoaActionPerformed
// TODO add your handling code here:
    int i = this.jtbDanhSachLoaiPhong.getSelectedRow();
    if(i == -1)
    {
        JOptionPane.showMessageDialog(this, "Xin vui lòng chọn loại phòng cần xóa");
    }
    else
    {
        try{
            if(JOptionPane.showConfirmDialog(this, "Bạn có chắc chắn  muốn xóa không ?", "Question",JOptionPane.YES_NO_OPTION)!=1)
            {
                int[] a = this.jtbDanhSachLoaiPhong.getSelectedRows();
                for(int t = 0; t< a.length; t++)
                {
                    if(!LoaiPhongCotroller.loaiPhong_Delete(jtbDanhSachLoaiPhong.getValueAt(a[t], 0).toString().substring(3)))
                    {
                        JOptionPane.showMessageDialog(rootPane, "Loại Phòng đang được dùng - Không thể xóa.","Warning",JOptionPane.WARNING_MESSAGE);
                        break;
                    }
                }
                this.LayDanhSachLoaiPhong();
            }
            else
            {
                return;
            }
        }
        catch(Exception e)
        {
             JOptionPane.showMessageDialog(new JFrame(), "Đường truyền bị gián đoạn ! Xin vui lòng kiểm tra lại", "Test Connect", JOptionPane.INFORMATION_MESSAGE);
        }
        this.txtLoaiPhong.setText("");
        this.txtGia.setText("");
    }
}//GEN-LAST:event_btnXoaActionPerformed

private void btnThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThemActionPerformed
// TODO add your handling code here:
    this.txtLoaiPhong.setEnabled(true);
    this.txtGia.setEnabled(true);
    this.txtLoaiPhong.setText("");
    this.txtGia.setText("");
    this.btnThem.setEnabled(false);
    this.btnXoa.setEnabled(false);
    this.btnSua.setEnabled(false);
    this.btnLuu.setEnabled(true);
    this.btnTroLai.setEnabled(true);
    frmPhong.flagLoaiPhong = 2;
}//GEN-LAST:event_btnThemActionPerformed

private void btnTroLaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTroLaiActionPerformed
// TODO add your handling code here:
    this.txtLoaiPhong.setEnabled(false);
    this.txtGia.setEnabled(false);
    this.btnThem.setEnabled(true);
    this.btnXoa.setEnabled(true);
    this.btnSua.setEnabled(true);
    this.btnLuu.setEnabled(false);
    if(this.jtbDanhSachLoaiPhong.getSelectedRow()!=-1)
    {
        this.LayThongTinLoaiPhong();
    }
    else
    {
        this.txtLoaiPhong.setText("");
        this.txtGia.setText("");
    }
    this.btnTroLai.setEnabled(false);
    frmPhong.flagLoaiPhong = 0;
}//GEN-LAST:event_btnTroLaiActionPerformed

private void txtGiaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtGiaKeyTyped
// TODO add your handling code here:
    char c = evt.getKeyChar();
    if(!Character.isDigit(c) )
    {
        evt.consume();
    }
}//GEN-LAST:event_txtGiaKeyTyped

private void jTabbedPane1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jTabbedPane1StateChanged
// TODO add your handling code here:
    // Tab Loại Phòng
    if(flagTab == 0)
    {
        this.txtLoaiPhong.setEnabled(!this.btnThem.isEnabled());
        this.txtGia.setEnabled(!this.btnThem.isEnabled());
        LayDanhSachLoaiPhong();
        flagTab = 1;
    }
    else // Tab Phòng
    {
        int i = 0;
        this.txtPhong.setEnabled(!this.btnThem2.isEnabled());
        this.txtPhong.setText("");
        LayDanhSachPhong();
        this.cmbLoaiPhong.removeAllItems();
        try{
            WebRowSet wrs = LoaiPhongCotroller.loaiPhong_GetByAll();
            combobox.clear();
            while(wrs.next())
            {
                this.cmbLoaiPhong.addItem(wrs.getObject("TenLoaiPhong").toString());
                combobox.add(wrs.getObject("MaLoaiPhong")+"");
                i++;
            }
        }
        catch(Exception e)
        {
             JOptionPane.showMessageDialog(new JFrame(), "Đường truyền bị gián đoạn ! Xin vui lòng kiểm tra lại", "Test Connect", JOptionPane.INFORMATION_MESSAGE);
        }
        flagTab = 0;
    }
}//GEN-LAST:event_jTabbedPane1StateChanged

private void jtDanhSachPhongMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtDanhSachPhongMousePressed
        LayThongTinPhong();
}//GEN-LAST:event_jtDanhSachPhongMousePressed

private void btnThem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThem2ActionPerformed
// TODO add your handling code here:
    this.txtPhong.setEnabled(true);
    this.cmbLoaiPhong.setEnabled(true);
//    this.cmbTinhTrang.setEnabled(true);
    cmbTinhTrang.setSelectedIndex(1);
    this.txaGhiChu.setEnabled(true);
    this.btnThem2.setEnabled(false);
    this.btnXoa2.setEnabled(false);
    this.btnSua2.setEnabled(false);
    this.btnLuu2.setEnabled(true);
    this.btnTroLai2.setEnabled(true);
    this.txtPhong.setText("");
    this.txaGhiChu.setText("");
    frmPhong.flagPhong = 2;
}//GEN-LAST:event_btnThem2ActionPerformed

private void btnSua2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSua2ActionPerformed
// TODO add your handling code here:
    int i = this.jtDanhSachPhong.getSelectedRow();
    if(i == -1)
    {
        JOptionPane.showMessageDialog(this, "Xin vui lòng chọn phòng cần sửa");
    }
    else
    {
        this.txtPhong.setEnabled(true);
        this.cmbLoaiPhong.setEnabled(true);
//        this.cmbTinhTrang.setEnabled(true);
        this.txaGhiChu.setEnabled(true);
        this.btnThem2.setEnabled(false);
        this.btnXoa2.setEnabled(false);
        this.btnLuu2.setEnabled(true);
        this.btnTroLai2.setEnabled(true);
        flagPhong = 1;
    }
}//GEN-LAST:event_btnSua2ActionPerformed

private void btnLuu2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLuu2ActionPerformed
// TODO add your handling code here:
    if(this.KiemTraTextbox(this.txtPhong, null))
        return;
    if(flagPhong == 1)//Sửa
    {
        PhongDTO p = new PhongDTO();
        p.setMaPhong(this.jtDanhSachPhong.getValueAt(this.jtDanhSachPhong.getSelectedRow(), 0).toString().substring(2));
        p.setMaLoaiPhong(combobox.get(this.cmbLoaiPhong.getSelectedIndex()).toString());
        p.setTenPhong(this.txtPhong.getText());
        p.setTinhTrang(String.valueOf(this.cmbTinhTrang.getSelectedIndex()));
        p.setGhiChu(this.txaGhiChu.getText());
        try{
            if(JOptionPane.showConfirmDialog(this, "Bạn có chắc chắn  muốn sửa không ?", "Question",JOptionPane.YES_NO_OPTION)!=1)
            {
                if(PhongController.phong_Update(p))
                {
                    this.LayDanhSachPhong();
//                    JOptionPane.showMessageDialog(this, "Sửa thành công !!");
                    this.txtPhong.setEnabled(false);
                    this.cmbLoaiPhong.setEnabled(false);
                    this.cmbTinhTrang.setEnabled(false);
                    this.txaGhiChu.setEnabled(false);
                    this.btnThem2.setEnabled(true);
                    this.btnXoa2.setEnabled(true);
                    this.btnSua2.setEnabled(true);
                    this.btnLuu2.setEnabled(false);
                    this.btnTroLai2.setEnabled(false);
                    frmPhong.flagPhong = 0;
                }
                else
                {
                    JOptionPane.showMessageDialog(this, "Lỗi.(Hai phòng cùng loại không được trùng tên !!)");
                }
            }
            else
            {
                return;
            }
        }
        catch(Exception e)
        {
             JOptionPane.showMessageDialog(new JFrame(), "Đường truyền bị gián đoạn ! Xin vui lòng kiểm tra lại", "Test Connect", JOptionPane.INFORMATION_MESSAGE);
        }
    }
    if(frmPhong.flagPhong == 2)//Thêm
    {
        PhongDTO p = new PhongDTO();
        p.setMaPhong(null);
        p.setMaLoaiPhong(combobox.get(this.cmbLoaiPhong.getSelectedIndex()).toString());
        p.setTenPhong(this.txtPhong.getText());
        p.setTinhTrang(String.valueOf(this.cmbTinhTrang.getSelectedIndex()));
        p.setGhiChu(this.txaGhiChu.getText());
        try{
            if(PhongController.phong_Insert(p))
            {
                this.LayDanhSachPhong();
                JOptionPane.showMessageDialog(this, "Thêm Thành Công !!");
                this.txtPhong.setEnabled(false);
                this.cmbLoaiPhong.setEnabled(false);
                this.cmbTinhTrang.setEnabled(false);
                this.txaGhiChu.setEnabled(false);
                this.btnThem2.setEnabled(true);
                this.btnXoa2.setEnabled(true);
                this.btnSua2.setEnabled(true);
                this.btnLuu2.setEnabled(false);
                this.btnTroLai2.setEnabled(false);
                flagPhong = 0;
            }
            else
            {
                JOptionPane.showMessageDialog(this, "Lỗi.(Hai phòng cùng loại không được trùng tên !!)");
            }
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(new JFrame(), "Đường truyền bị gián đoạn ! Xin vui lòng kiểm tra lại", "Test Connect", JOptionPane.INFORMATION_MESSAGE);
        }
    }
}//GEN-LAST:event_btnLuu2ActionPerformed

private void btnTroLai2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTroLai2ActionPerformed
// TODO add your handling code here:
    this.txtPhong.setEnabled(false);
    this.cmbLoaiPhong.setEnabled(false);
    this.cmbTinhTrang.setEnabled(false);
    this.txaGhiChu.setEnabled(false);
    this.btnThem2.setEnabled(true);
    this.btnXoa2.setEnabled(true);
    this.btnSua2.setEnabled(true);
    this.btnLuu2.setEnabled(false);
    if(this.jtDanhSachPhong.getSelectedRow()!=-1)
    {
        this.LayThongTinPhong();
    }
    else
    {
        this.txtPhong.setText("");
        this.txaGhiChu.setText("");
    }
    this.btnTroLai2.setEnabled(false);
    frmPhong.flagPhong = 0;
}//GEN-LAST:event_btnTroLai2ActionPerformed

private void btnXoa2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnXoa2ActionPerformed
// TODO add your handling code here:
    int i = this.jtDanhSachPhong.getSelectedRow();
    if(i == -1)
    {
        JOptionPane.showMessageDialog(this, "Xin vui lòng chọn phòng cần xóa");
    }
    else
    {
        try{
            if(JOptionPane.showConfirmDialog(this, "Bạn có chắc chắn  muốn xóa không ?", "Question",JOptionPane.YES_NO_OPTION)!=1)
            {
                int[] a = this.jtDanhSachPhong.getSelectedRows();
                for(int t = 0; t< a.length; t++)
                {
                    if(!PhongController.phong_Delete(jtDanhSachPhong.getValueAt(a[t], 0).toString().substring(2)))
                    {
                        JOptionPane.showMessageDialog(rootPane, "Phòng đang được dùng - Không thể xóa.","Warning",JOptionPane.WARNING_MESSAGE);
                        break;
                    }
                }
                this.LayDanhSachPhong();
            }
            else
            {
                return;
            }
        }
        catch(Exception e)
        {
             JOptionPane.showMessageDialog(new JFrame(), "Đường truyền bị gián đoạn ! Xin vui lòng kiểm tra lại", "Test Connect", JOptionPane.INFORMATION_MESSAGE);
        }
//        JOptionPane.showMessageDialog(this, "Xóa thành công !!");
        this.txtPhong.setText("");
        this.txaGhiChu.setText("");
    }
}//GEN-LAST:event_btnXoa2ActionPerformed

private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
    frmMain._main.setVisible(true);
    frmMain._main.setFocusable(true);
    // TODO add your handling code here:
}//GEN-LAST:event_formWindowClosed

private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
// TODO add your handling code here:
      LayDanhSachLoaiPhong();
      LayDanhSachPhong();
}//GEN-LAST:event_formComponentShown

private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed
// TODO add your handling code here:
    try{
        MaLP.clear();
        WebRowSet wrs = PhongController.phong_GetByTop("", " TenPhong LIKE '"+this.txtSearch.getText()+"%' ", "");
        String[] tableColumnsName = {"Mã Phòng","Tên Phòng", "Mã Loại Phòng", "Loại Phòng", "Trạng Thái", "Ghi Chú"};
        if(wrs.size() > 0)
        {
            DefaultTableModel dfTable = (DefaultTableModel) this.jtDanhSachPhong.getModel();
            dfTable.getDataVector().removeAllElements();
            dfTable.setColumnIdentifiers(tableColumnsName);
            Vector rowData;
            String[] tinhtrang = {"Đã Thuê", "Trống"};
            while(wrs.next()){
                rowData = new Vector() ;
                rowData.add ("MP"+wrs.getString("MaPhong"));
                rowData.add (wrs.getString("TenPhong"));
                WebRowSet rs = LoaiPhongCotroller.loaiPhong_GetById(wrs.getString("MaLoaiPhong").toString());
                while(rs.next())
                {
                    rowData.add("MLP"+rs.getString("MaLoaiPhong"));
                    MaLP.add(wrs.getString("MaLoaiPhong"));
                    rowData.add(rs.getString("TenLoaiPhong"));
                }
                rowData.add(tinhtrang[wrs.getInt("TinhTrang")]);
                rowData.add(wrs.getString("GhiChu"));
                dfTable.addRow(rowData);
            }

            this.txtSearch.setText("");
        }
        else
        {
            JOptionPane.showMessageDialog(this, "Không có phòng nào giống phòng cần tìm. Vui lòng nhập lại !!");
            wrs = PhongController.phong_GetByAll();
            this.UpdateTable(jtDanhSachPhong, tableColumnsName, wrs);
            this.txtSearch.setText("");
        }
    }
    catch(Exception e)
    {
        
    }
}//GEN-LAST:event_btnSearchActionPerformed

private void btnPrintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrintActionPerformed

    try {
            // TODO add your handling code here:
            String html1 = "";//<meta http-equiv=Content-Type content='text/html; charset=utf8'>";
            //<LEFT>CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM</BR>----------Ðộc lập - Tự do - Hạnh phúc-----------</LEFT>";
            html1 += "<CENTER><h2>DANH SÁCH LOẠI PHÒNG</h2>"; 
            String footer ="";
            BaoCao bc = new BaoCao();
            bc.baocao(jtbDanhSachLoaiPhong,html1,footer,"400");
        } catch (Exception ex) {
//            Logger.getLogger(frmBaoCao.class.getName()).log(Level.SEVERE, null, ex);
        }

    // TODO add your handling code here:
}//GEN-LAST:event_btnPrintActionPerformed

private void btnPrint1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrint1ActionPerformed
    try {
            // TODO add your handling code here:
            String html1 = "";//<meta http-equiv=Content-Type content='text/html; charset=utf8'>";
            //html1 += "<LEFT>CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM</BR>----------Ðộc lập - Tự do - Hạnh phúc-----------</LEFT>";
            html1 += "<CENTER><h2>DANH SÁCH PHÒNG</h2>"; 

            String footer ="";

            BaoCao bc = new BaoCao();
            bc.baocao(jtDanhSachPhong,html1,footer,"400");
        } catch (Exception ex) {
//            Logger.getLogger(frmBaoCao.class.getName()).log(Level.SEVERE, null, ex);
        }
    // TODO add your handling code here:
}//GEN-LAST:event_btnPrint1ActionPerformed

private void jPanel2ComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jPanel2ComponentShown

//    try
//    {
//        UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");//set giao dien
//    }
//    catch(Exception e)
//    {}
    // TODO add your handling code here:
}//GEN-LAST:event_jPanel2ComponentShown

///<editor-fold defaultstate="collapsed" desc=" Format_Price ">
    private String Format_Price(String Price)
        {
            if ("0".equals(Price))
            {
                return "0";
            }
            else
                Price = Price.replace(".0", "");
            Price = Price.replace(",", "");
            String tmp = "";
            while (Price.length() > 3)
            {
                tmp = "." + Price.substring(Price.length() - 3) + tmp;
                Price = Price.substring(0, Price.length() - 3);
            }
            tmp = Price + tmp ;
            return tmp;
        }
    //</editor-fold>

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frmPhong.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frmPhong.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frmPhong.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frmPhong.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new frmPhong().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnLuu;
    private javax.swing.JButton btnLuu2;
    private javax.swing.JButton btnPrint;
    private javax.swing.JButton btnPrint1;
    private javax.swing.JButton btnSearch;
    private javax.swing.JButton btnSua;
    private javax.swing.JButton btnSua2;
    private javax.swing.JButton btnThem;
    private javax.swing.JButton btnThem2;
    private javax.swing.JButton btnTroLai;
    private javax.swing.JButton btnTroLai2;
    private javax.swing.JButton btnXoa;
    private javax.swing.JButton btnXoa2;
    private javax.swing.JComboBox cmbLoaiPhong;
    private javax.swing.JComboBox cmbTinhTrang;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jtDanhSachPhong;
    private javax.swing.JTable jtbDanhSachLoaiPhong;
    private javax.swing.JTextArea txaGhiChu;
    private javax.swing.JTextField txtGia;
    private javax.swing.JTextField txtLoaiPhong;
    private javax.swing.JTextField txtPhong;
    private javax.swing.JTextField txtSearch;
    // End of variables declaration//GEN-END:variables
}
